package com.hdu.dwh.utils;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 操作人工具类，用于获取当前操作人信息
 */
public class OperatorUtil {

    /**
     * 获取当前操作人
     * @return 当前操作人用户名
     */
    public static String getCurrentOperator() {
        try {
            HttpServletRequest request =
                    ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            return (String) request.getAttribute("currentUsername");
        } catch (Exception e) {
            return "unknown";
        }
    }
}

